<template>
	<!-- 提示确认框 -->
	<Popup ref="popup" type="center" :mask-click="false" class="Popup" :catchtouchmove="true">
		<view class="slot-view">
			<!-- 标题 -->
			<view class="title" v-if="title" :style="{fontSize: titleSize+'rpx',padding: titlePadding}">
				<text>{{title}}</text>
				<image src="/static/mine/model_popup_close.png" mode="" @click="cancel()" v-if="showCloseIcon"></image>
			</view>
			<!-- 内容 -->
			<view class="toast-text" :style="{textAlign: align,padding: contentPadding}">
				<text>
					{{content}}
				</text>
			</view>
			<!-- 按钮组 -->
			<view v-if="payNoticeItem==1" class="btn-box" :class="{'-active': showCancel && showConfirm}">
				<view class="cancel-btn" hover-class="hover-class" @click="confirm()" v-if="showCancel" :style="{
					color: cancelColor 
				}" :class="{'-active':showCancel && showConfirm}">
					<text>{{confirmText}}</text>
				</view>
				
				<view class="confirm-btn" @click="home()" v-if="showConfirm" :style="{
					color:confirmColor
				}" :class="{'-active':showCancel && showConfirm}">
					<text>{{goHomeText}}</text>
				</view>
			</view>
			
			<view v-if="payNoticeItem==2" class="btn-box" :class="{'-active': showCancel && showConfirm}">
				<view class="cancel-btn" hover-class="hover-class" @click="cancel()" v-if="showCancel" :style="{
					color: cancelColor 
				}" :class="{'-active':showCancel && showConfirm}">
					<text>{{cancelText}}</text>
				</view>
				
				<view class="confirm-btn" @click="goMap()" v-if="showConfirm" :style="{
					color:confirmColor
				}" :class="{'-active':showCancel && showConfirm}">
					<text>{{goMapText}}</text>
				</view>
			</view>
			
			<!-- 获取用户手机号提示 -->
			<view v-if="payNoticeItem==3" class="btn-box" :class="{'-active': showCancel && showConfirm}">
				<view class="cancel-btn" hover-class="hover-class" @click="cancel()" v-if="showCancel" :style="{
					color: cancelColor 
				}" :class="{'-active':showCancel && showConfirm}">
					<text>{{cancelText}}</text>
				</view>
				
				<!--  #ifdef MP-WEIXIN  -->
				<button open-type="getPhoneNumber" @getphonenumber="phoneLogin"  class="logon-phone">
					<text style="color: #FFFFFF">绑定手机号</text>
				</button>
				<!-- #endif -->
			</view>
			
		</view>
	</Popup>
</template>

<script>
	import Popup from '@/uni_modules/uni-popup/components/uni-popup/uni-popup.vue';
	import api from '@/api/mine.js';
	export default {
		props: {
			// 标题
			title: {
				type: String,
				default: ""
			},
			// 标题大小
			titleSize: {
				type: [String, Number],
				default: 40
			},
			// 提示内容
			content: {
				type: String,
				default: ""
			},
			space:{
				type: Boolean,
				default: true
			},
			// show cancel btn
			showCancel: {
				type: Boolean,
				default: true
			},
			// show confirm btn
			showConfirm: {
				type: Boolean,
				default: true
			},
			// 取消图标
			showCloseIcon: {
				type: Boolean,
				default: false
			},
			// 文字对齐方式
			align: {
				type: String,
				default: 'center'
			},
			// 标题内边距
			titlePadding:{
				type: String,
				default: "20rpx 30rpx"
			},
			// 内容内边距
			contentPadding: {
				type: String,
				default: "20rpx 20rpx 40rpx"
			},
			// 取消文字
			cancelText: {
				type: String,
				default: "我知道了"
			},
			// 确认文字
			confirmText: {
				type: String,
				default: "继续支付"
			},
			// 重新选站
			goHomeText: {
				type: String,
				default: "重新选站"
			},
			//导航到加油站
			goMapText:{
				type: String,
				default: "导航到加油站"
			},
			goPhoneText:{
				type:String,
				default: "绑定手机号"
			},
			cancelColor: {
				type: String,
				default: "#222"
			},
			confirmColor: {
				type: String,
				default: "#FFF"
			},
			lat:{
				type: [String, Number],
				default:0,
			},
			lng:{
				type: [String, Number],
				default:0,
			},
			station_name:{
				type: String,
				default: ""
			},
			station_address:{
				type: String,
				default: ""
			},
			payNoticeItem:{
				type: [String, Number],
				default:0
			}
			
		},
		components: {
			Popup
		},
		data() {
			return {
				form: {
					code: '', //授权码
					userInfo: '', //用户基本信息
					iv: '', //获取手机号必填
					encryptedData: '',
					invite: '' //邀请码
				},
			}
		},
		methods: {
			home() {
				uni.reLaunch({
				  url: '/pages/home/index',
				  animationType: 'pop-out',
				  animationDuration: 200
				})
			},
			cancel() {
				this.$refs.popup.close();
				this.$emit('close');
				uni.setStorage({ key: 'is_hide',data:1	})
			},
			open() {
				this.$refs.popup.open('center');
			},
			confirm() {
				this.$refs.popup.close();
				this.$emit('confirm');
			},
			goMap(){
				uni.openLocation({
					latitude: Number(this.lat),
					longitude: Number(this.lng),
					name: this.station_name,
					address:this.station_address,
					success: function() {
						// console.log('success');
					},
					fail: function(res) {
						if (res.errMsg == "getLocation:fail auth deny") {
							uni.showModal({
								content: '检测到您没打开获取信息功能权限，是否去设置打开？',
								confirmText: "确认",
								cancelText: '取消',
								success: (res) => {
									if (res.confirm) {
										uni.openSetting({
											success: (res) => {
												// console.log('确定');
											}
										})
									} else {
										// console.log('取消');
										return false;
									}
								}
							})
						}
					}
				});
							
			},
	    // 微信登录
		phoneLogin(e) {
			let _this = this
			uni.login({
				success: (log) => {
					_this.form.code = log.code;
					uni.setStorage({ key: 'is_hide',data:1	})
					if (e.detail.errMsg == 'getPhoneNumber:ok' && _this.form.code!='') {
						_this.form.iv = e.detail.iv, //获取手机号必填
							_this.form.encryptedData = e.detail.encryptedData
							
							api.login(_this.form).then(res => {
								
								if (res.code == 1) {
									uni.setStorageSync('userinfo', res.data
										.userinfo);
									this.cancel();
									uni.setStorage({ key: 'is_register',data:1	})
								} else {
									uni.showToast({
										title: res.msg,
										icon: 'none',
										duration: 2000
									});
								}
							})
							
					} else {
						uni.showToast({
							title: '您已取消授权!',
							icon: 'none'
							// dur
						})
					}
				}
			});
			
			
		},
	
		}
	}
</script>

<style lang="scss" scoped>
	.slot-view {
		width: 90vw;
		padding: 30rpx 40rpx;
		box-sizing: border-box;
		background-color: #fff;
		border-radius: 20rpx;
		border: 2rpx solid #7c7c7c;


		.title {
			position: relative;
			color: #1a1a1a;
			// padding-top: 20rpx;
			// padding-bottom: 20rpx;
			// padding-left: 30rpx;
			// padding-right: 30rpx;
			text-align: center;

			image {
				width: 36rpx;
				height: 36rpx;
				position: absolute;
				right: 0;
				top: 50%;
				transform: translateY(-50%);
			}
		}

		.toast-text {
			line-height: 50rpx;
			font-size: 30rpx;
			color: #343434;
			font-family: '宋体';
			max-height: 70vh;
			overflow: hidden;
		}

		.btn-box {

			&.-active {
				display: flex;
				justify-content: space-between;
				align-items: center;
			}

			.cancel-btn {
				font-size: 32rpx;
				text-align: center;
				padding: 16rpx 0;
				border: 2rpx solid #cbcbcb;
				border-radius: 10rpx;
				box-sizing: border-box;

				&.-active {
					width: 47%;
				}

				&.hover-class {
					background-color: #F7F7F7;
				}
			}

			.confirm-btn {
				font-size: 32rpx;
				text-align: center;
				padding: 16rpx 0;
				border-radius: 10rpx;
				background-color: #F12F63;

				&.-active {
					width: 47%;
				}
			}
			
			.logon-phone {
				font-size: 32rpx;
				text-align: center;
				padding: 16rpx 0;
				border-radius: 10rpx;
				color: #FFFFFF !important;
				background: #f6424d;
				border: none;
				width: 47%;
				line-height: 50rpx;
			}

		}
	}
</style>
